package com.bytz.modules.system.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytz.common.api.vo.Result;
import com.bytz.common.constant.CommonConstant;
import com.bytz.common.exception.BytzBootException;
import com.bytz.common.system.api.ISysBaseApi;
import com.bytz.common.system.query.QueryGenerator;
import com.bytz.common.system.vo.LoginUser;
import com.bytz.common.util.SecurityUtils;
import com.bytz.common.util.oConvertUtils;
import com.bytz.modules.cms.user.entity.CmsSysUser;
import com.bytz.modules.cms.user.service.ICmsSysUserService;
import com.bytz.modules.system.constant.SysAuthConstants;
import com.bytz.modules.system.entity.SysDepart;
import com.bytz.modules.system.entity.SysUser;
import com.bytz.modules.system.entity.SysUserDepart;
import com.bytz.modules.system.entity.SysUserRole;
import com.bytz.modules.system.model.DepartIdModel;
import com.bytz.modules.system.model.SysUserOut;
import com.bytz.modules.system.service.ISysDepartService;
import com.bytz.modules.system.service.ISysUserDepartService;
import com.bytz.modules.system.service.ISysUserRoleService;
import com.bytz.modules.system.service.ISysUserService;
import com.bytz.modules.system.vo.SysDepartUsersVO;
import com.bytz.modules.system.vo.SysUserRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @Author scott
 * @since 2018-12-20
 */
@Slf4j
@RestController
@Api(tags = "系统用户")
@RequestMapping("/sys/user")
public class SysUserController {
    @Autowired
    private ISysBaseApi sysBaseApi;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysDepartService sysDepartService;

    @Autowired
    private ISysUserRoleService sysUserRoleService;

    @Autowired
    private ISysUserDepartService sysUserDepartService;

    @Autowired
    private ICmsSysUserService cmsSysUserService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_VIEW + "')")
    public Result<IPage<CmsSysUser>> queryPageList(CmsSysUser user, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        LambdaQueryWrapper<CmsSysUser> queryWrapper = QueryGenerator.initLambdaQueryWrapper(user, req.getParameterMap());
        queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysUser::getId);
        Page<CmsSysUser> page = new Page<>(pageNo, pageSize);

        return Result.ok(cmsSysUserService.page(page, queryWrapper));
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<CmsSysUser> add(@RequestBody JSONObject jsonObject) {
        String selectedRoles = jsonObject.getString("selectedroles");
        String selectedDeparts = jsonObject.getString("selecteddeparts");
        CmsSysUser user = JSON.parseObject(jsonObject.toJSONString(), CmsSysUser.class);

        return Result.ok(cmsSysUserService.addUser(user, selectedRoles, selectedDeparts));
    }

    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
        SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
        sysBaseApi.addLog("编辑用户，id： " + jsonObject.getString("id"), CommonConstant.LOG_TYPE_2, 2);
        if (sysUser == null) {
            throw new BytzBootException("用户不存在");
        }
        CmsSysUser user = JSON.parseObject(jsonObject.toJSONString(), CmsSysUser.class);
        String roles = jsonObject.getString("selectedroles");
        String departs = jsonObject.getString("selecteddeparts");

        cmsSysUserService.editUser(user, roles, departs);

        return Result.ok(user);
    }

    /**
     * 删除用户
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        sysBaseApi.addLog("删除用户，id： " + id, CommonConstant.LOG_TYPE_2, 3);
        SysUser user = sysUserService.getById(id);
        if (user == null) {
            throw new BytzBootException("找不到用户");
        }

        return Result.ok("删除用户成功", this.sysUserService.deleteUser(user));
    }

    /**
     * 批量删除用户
     */
    @RequestMapping(value = "/deleteBatch", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        sysBaseApi.addLog("批量删除用户， ids： " + ids, CommonConstant.LOG_TYPE_2, 3);
        this.sysUserService.deleteBatchUsers(ids);
        return Result.ok("批量删除用户成功");
    }

    /**
     * 冻结&解冻用户
     *
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/frozenBatch", method = {RequestMethod.PUT, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<?> frozenBatch(@RequestBody JSONObject jsonObject) {
        String ids = jsonObject.getString("ids");
        String status = jsonObject.getString("status");
        List<String> userIds = Arrays.stream(ids.split(","))
                .filter(StrUtil::isNotBlank)
                .collect(Collectors.toList());

        sysUserService.frozenBatch(userIds, status);

        return Result.ok("操作成功!");
    }

    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_VIEW + "')")
    public Result<SysUser> queryById(@RequestParam(name = "id", required = true) String id) {
        SysUser sysUser = sysUserService.getById(id);
        if (sysUser == null) {
            throw new BytzBootException("未找到用户");
        }

        return Result.ok(sysUser);
    }

    @RequestMapping(value = "/queryUserRole", method = RequestMethod.GET)
    public Result<List<String>> queryUserRole(@RequestParam(name = "userid", required = true) String userid) {
        Result<List<String>> result = new Result<>();
        List<String> list = new ArrayList<String>();
        List<SysUserRole> userRole = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userid));
        if (userRole == null || userRole.size() <= 0) {
            result.error500("未找到用户相关角色信息");
        } else {
            for (SysUserRole sysUserRole : userRole) {
                list.add(sysUserRole.getRoleId());
            }
            result.setSuccess(true);
            result.setResult(list);
        }
        return result;
    }


    /**
     * 校验用户账号是否唯一<br>
     * 可以校验其他 需要检验什么就传什么。。。
     *
     * @param sysUser
     * @return
     */
    @RequestMapping(value = "/checkOnlyUser", method = RequestMethod.GET)
    public Result<Boolean> checkOnlyUser(SysUser sysUser) {
        //通过传入信息查询新的用户信息
        SysUser user = sysUserService.getOne(new QueryWrapper<SysUser>(sysUser));
        if (user != null) {
            return Result.error("用户账号已存在");
        }

        return Result.ok();
    }

    /**
     * 修改密码
     */
    @RequestMapping(value = "/changPassword", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<?> changPassword(@RequestBody SysUser sysUser) {
        sysUserService.changePassword(sysUser.getUsername(), sysUser.getPassword());
        return Result.ok("密码修改成功!");
    }

    /**
     * 查询指定用户和部门关联的数据
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询指定用户和部门关联的数据", notes = "查询指定用户和部门关联的数据")
    @RequestMapping(value = "/userDepartList", method = RequestMethod.GET)
    public Result<List<DepartIdModel>> getUserDepartsList(@RequestParam(name = "userId") String userId) {
        return Result.ok(this.sysUserDepartService.queryDepartIdsOfUser(userId));
    }

    /**
     * 生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据
     *
     * @return
     */
    @RequestMapping(value = "/generateUserId", method = RequestMethod.GET)
    public Result<String> generateUserId() {
        return Result.ok(UUID.randomUUID().toString().replace("-", ""));
    }


    /**
     * 根据部门id查询用户信息
     */
    @ApiOperation(value = "根据部门id查询用户信息", notes = "根据部门id查询用户信息")
    @RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
    public Result<List<SysUserOut>> queryUserByDepId(@RequestParam(name = "id", required = true) String id,
                                                     @RequestParam(name = "keyword", required = false) String keyword) {
        List<SysUser> userList = sysUserDepartService.queryUserByDepId(id, keyword);

        return Result.ok(toSysUserOut(userList));
    }

    /**
     * 导出excel
     *
     * @param sysUser
     * @param request
     */
    @RequestMapping(value = "/exportXls")
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_VIEW + "')")
    public ModelAndView exportXls(SysUser sysUser, HttpServletRequest request) {
        // Step.1 组装查询条件
        QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(sysUser, request.getParameterMap());
        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //update-begin--Author:kangxiaolin  Date:20180825 for：[03]用户导出，如果选择数据则只导出相关数据--------------------
        String selections = request.getParameter("selections");
        if (!oConvertUtils.isEmpty(selections)) {
            queryWrapper.in("id", selections.split(","));
        }
        //update-end--Author:kangxiaolin  Date:20180825 for：[03]用户导出，如果选择数据则只导出相关数据----------------------
        List<SysUser> pageList = sysUserService.list(queryWrapper);

        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "用户列表");
        mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
        LoginUser user = SecurityUtils.getLoginUser();
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户列表数据", "导出人:" + user.getRealname(), "导出信息"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<SysUser> listSysUsers = ExcelImportUtil.importExcel(file.getInputStream(), SysUser.class, params);
                for (SysUser sysUserExcel : listSysUsers) {
                    if (sysUserExcel.getPassword() == null) {
                        // 密码默认为“123456”
                        sysUserExcel.setPassword("123456");
                    }
                    sysUserService.save(sysUserExcel);
                }
                return Result.ok("文件导入成功！数据行数：" + listSysUsers.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("抱歉! 您导入的数据中用户名已经存在.");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    /**
     * @param userIds
     * @return
     * @功能：根据id 批量查询
     */
    @ApiOperation(value = "根据userId 批量查询", notes = "根据userId 批量查询")
    @RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
    public Result<Collection<SysUserOut>> queryByIds(@RequestParam String userIds) {
        Result<Collection<SysUserOut>> result = new Result<>();
        String[] userId = userIds.split(",");
        Collection<String> idList = Arrays.asList(userId);
        Collection<SysUser> users = sysUserService.listByIds(idList);
        result.setSuccess(true);
        result.setResult(toSysUserOut(users));
        return result;
    }

    /**
     * 首页用户重置密码
     */
    @RequestMapping(value = "/updatePassword", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<?> changPassword(@RequestBody JSONObject json) {
        String username = json.getString("username");
        String oldpassword = json.getString("oldpassword");
        String password = json.getString("password");
        String confirmpassword = json.getString("confirmpassword");

        return sysUserService.resetPassword(username, oldpassword, password, confirmpassword);
    }

    @RequestMapping(value = "/userRoleList", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.RolePermission.ROLE_VIEW + "')")
    public Result<IPage<SysUser>> userRoleList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<SysUser>> result = new Result<>();
        Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
        String roleId = req.getParameter("roleId");
        String username = req.getParameter("username");
        IPage<SysUser> pageList = sysUserService.getUserByRoleId(page, roleId, username);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 给指定角色添加用户
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/addSysUserRole", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<String> addSysUserRole(@RequestBody SysUserRoleVO sysUserRoleVO) {
        sysUserService.addUserRole(sysUserRoleVO);
        return Result.ok("添加成功!");
    }

    /**
     * 删除指定角色的用户关系
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteUserRole", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<SysUserRole> deleteUserRole(@RequestParam(name = "roleId") String roleId,
                                              @RequestParam(name = "userId") String userId) {
        sysUserRoleService.removeByUserAndRole(userId, roleId);

        return Result.ok("删除成功!");
    }

    /**
     * 批量删除指定角色的用户关系
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteUserRoleBatch", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<SysUserRole> deleteUserRoleBatch(@RequestParam(name = "roleId") String roleId,
                                                   @RequestParam(name = "userIds", required = true) String userIds) {
        sysUserRoleService.removeByUsersAndRole(StrUtil.split(userIds, ","), roleId);
        return Result.ok("删除成功!");
    }

    /**
     * 部门用户列表
     */
    @ApiOperation(value = "部门用户列表", notes = "部门用户列表")
    @RequestMapping(value = "/departUserList", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_VIEW + "')")
    public Result<IPage<SysUser>> departUserList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                 @RequestParam(name = "depId", required = true) String depId,
                                                 @RequestParam(name = "username", required = false) String username) {
        Page<SysUser> page = new Page<>(pageNo, pageSize);

        return Result.ok(sysUserService.getUserByDepId(page, depId, username));
    }

    /**
     * 根据 orgCode 查询用户，包括子部门下的用户
     * 针对通讯录模块做的接口，将多个部门的用户合并成一条记录，并转成对前端友好的格式
     */
    @ApiOperation(value = "根据 orgCode 查询用户，包括子部门下的用户(合并用户)", notes = "针对通讯录模块做的接口，将多个部门的用户合并成一条记录，并转成对前端友好的格式")
    @GetMapping("/queryByOrgCodeForAddressSelector")
    public Result<?> queryByOrgCodeForAddressSelector(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(name = "orgCode", required = false) String orgCode,
                                                      @RequestParam(name = "roleCode", required = false) String roleCode,
                                                      @RequestParam(name = "querySubDept", required = false, defaultValue = "true") Boolean querySubDept,
                                                      SysUser userParams) {

        IPage<?> page = new Page<>(pageNo, pageSize);
        return Result.ok(sysUserService.queryByOrgCodeForAddress(orgCode, userParams, roleCode, page, true, querySubDept));
    }

    /**
     * 根据 orgCode 查询用户，包括子部门下的用户
     * 针对通讯录模块做的接口，将多个部门的用户合并成一条记录，并转成对前端友好的格式
     */
    @ApiOperation(value = "根据 orgCode 查询用户，包括子部门下的用户(合并用户)", notes = "针对通讯录模块做的接口，将多个部门的用户合并成一条记录，并转成对前端友好的格式")
    @GetMapping("/queryByOrgCodeForAddressList")
    @PreAuthorize("hasAuthority('" + SysAuthConstants.AddressListPermission.ADDRESS_LIST_VIEW + "')")
    public Result<?> queryByOrgCodeForAddressList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(name = "orgCode", required = false) String orgCode,
                                                  @RequestParam(name = "roleCode", required = false) String roleCode,
                                                  @RequestParam(name = "querySubDept", required = false, defaultValue = "true") Boolean querySubDept,
                                                  SysUser userParams) {

        IPage<?> page = new Page<>(pageNo, pageSize);
        return Result.ok(sysUserService.queryByOrgCodeForAddress(orgCode, userParams, roleCode, page, false, querySubDept));
    }

    /**
     * 给指定部门添加对应的用户
     */
    @RequestMapping(value = "/editSysDepartWithUser", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<String> editSysDepartWithUser(@RequestBody SysDepartUsersVO sysDepartUsersVO) {
        sysUserService.editSysDepartWithUser(sysDepartUsersVO);
        return Result.ok("操作成功");
    }

    /**
     * 删除指定机构的用户关系
     */
    @RequestMapping(value = "/deleteUserInDepart", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<SysUserDepart> deleteUserInDepart(@RequestParam(name = "depId") String depId,
                                                    @RequestParam(name = "userId", required = true) String userId) {
        sysUserService.deleteUserInDepart(depId, userId);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除指定机构的用户关系
     */
    @RequestMapping(value = "/deleteUserInDepartBatch", method = {RequestMethod.DELETE, RequestMethod.POST})
    @PreAuthorize("hasAuthority('" + SysAuthConstants.UserPermission.USER_EDIT + "')")
    public Result<SysUserDepart> deleteUserInDepartBatch(@RequestParam(name = "depId") String depId,
                                                         @RequestParam(name = "userIds") String userIds) {
        for (String id : userIds.split(",")) {
            sysUserService.deleteUserInDepart(depId, id);
        }

        return Result.ok("删除成功!");
    }

    /**
     * 查询当前用户的所有部门/当前部门编码
     *
     * @return
     */
    @ApiOperation(value = "查询当前用户的所有部门/当前部门编码", notes = "查询当前用户的所有部门/当前部门编码")
    @RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
    public Result<Map<String, Object>> getCurrentUserDeparts() {
        LoginUser sysUser = SecurityUtils.getLoginUser();
        List<SysDepart> list = this.sysDepartService.queryUserDeparts(sysUser.getId());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        map.put("orgCode", sysUser.getOrgCode());

        return Result.ok(map);
    }

    /**
     * 进行脱敏处理
     */
    private <U extends SysUser> List<SysUserOut> toSysUserOut(Collection<U> in) {
        List<SysUserOut> result = new ArrayList<>(in.size());
        for (SysUser sysUser : in) {
            SysUserOut sysUserOut = BeanUtil.toBean(sysUser, SysUserOut.class);
            sysUserOut.setPhone(DesensitizedUtil.mobilePhone(sysUser.getPhone()));
            sysUserOut.setTelephone(DesensitizedUtil.mobilePhone(sysUser.getTelephone()));

            result.add(sysUserOut);
        }

        return result;
    }

    @ApiOperation(value = "根据产品线id查询销售", notes = "根据产品线id查询销售")
    @RequestMapping(value = "/getSalesByProductLine", method = RequestMethod.GET)
    public List<SysUserOut> getSales(@RequestParam String productLineId) {
        return toSysUserOut(cmsSysUserService.getSales(productLineId));
    }

    @ApiOperation(value = "根据登录人的产品线查询销售", notes = "根据登录人的产品线查询销售")
    @RequestMapping(value = "/getSales", method = RequestMethod.GET)
    public List<SysUserOut> getSales() {
        return toSysUserOut(cmsSysUserService.getSales(null));
    }

    @ApiOperation(value = "根据角色code查询用户", notes = "根据角色code查询用户")
    @RequestMapping(value = "/getByRoleCode", method = RequestMethod.GET)
    public Result<List<SysUserOut>> getByRoleCode(@RequestParam String roleCode) {
        return Result.ok(toSysUserOut(cmsSysUserService.getUsersByRoleCode(roleCode)));
    }
}
